package com.smartao.base.setting;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.smartao.base.Constant;
import com.smartao.base.init.InitializeServiceOrder;
import com.smartao.base.module.Module;
import com.smartao.base.module.ModuleService;
import com.smartao.core.init.AbstractDataInitializeService;

@Service
public class SettingInitializeService extends AbstractDataInitializeService{

	@Autowired
	private ModuleService moduleService;
	@Autowired
	private SettingService settingService;
	
	@Override
	public int getOrder() {
		return InitializeServiceOrder.INIT_ORDER_SETTING;
	}

	@Override
	public void initData() throws Exception {
		String[][] ss = new String[][]{
			// 页面设置
			{"page.style", "default"},
			
			// 文档设置
			{"doc.enableZip", "0"},
			{"doc.rootPath", "e:/smartao/docs/"},
			{"doc.attachementSize", "300"},
			{"doc.ftpRootPath", "e:/smartao/ftp"},
			
			// 登录设置
			{"login.enableCaptcha", "false"},
			{"login.enableSSO", "false"},
			{"login.enableRemember", "false"},
			{"login.enableUSB", "false"},
			{"login.enableDynamicpass", "false"},
			{"login.providers", "DaoAuthenticationProvider"},
			{"login.maximumSessions", "-1"},
			{"login.maximumException", "false"},
			
			// 密码设置
			{"password.minLength", "6"},
			{"password.maxLength", "8"},
			{"password.age", "-1"},
			{"password.uppercaseRequired", "false"},
			{"password.lowercaseRequired", "true"},
			{"password.digitRequired", "true"},
			{"password.nonAlphanumericRequired", "false"},
			
			// 消息提醒设置 - 邮件
			{"email.enabled", "true"},
			{"email.host", "mail"},
			{"email.port", "25"},
			{"email.fromAddress", "oa"},
			{"email.prefix", ""},
			{"email.protocol", ""},
			{"email.timeout", ""},
			{"email.tlsRequired", ""},
			{"email.username", "oa"},
			{"email.password", "oa"},
			
			// 消息提醒设置 - 短信
			// sms = short message service
			{"sms.enabled", "false"},
			{"sms.suffix", "[SmartAO]"},
			{"sms.account", ""},
			{"sms.password", ""}
		};
		
		Setting st = settingService.findByKey("page.style");
		if(st!=null){
			return;
		}
		Module m = moduleService.findByModuleKey(Constant.MODULE_BASE);
		for(String[] s : ss){
			Setting setting = new Setting(s[0], s[1], m);
			settingService.save(setting);
		}
	}

}
